package com.example.ccj.b.c.custom;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.DashPathEffect;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;

import androidx.annotation.Nullable;

/**
 * 虚线
 * 2022年9月16日16:58:13
 */
public class ShowDashLineView extends View {
    private Paint mPaint;

    public ShowDashLineView(Context context) {
        super(context);
        init(context);
    }

    public ShowDashLineView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public ShowDashLineView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
    }

    private void init(Context context){
        mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        mPaint.setColor(Color.parseColor("#dddddd"));
        mPaint.setStrokeWidth(10);
        mPaint.setPathEffect(new DashPathEffect(new float[]{5,5},0));

    }

    @Override
    protected void onDraw(Canvas canvas) {
        int centerY = getHeight()/2;
        setLayerType(LAYER_TYPE_SOFTWARE,null);
        canvas.drawLine(0,centerY,getWidth(),centerY,mPaint);
    }
}
